<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="终端ID" prop="terminal">
        <el-input
          v-model="queryParams.terminal"
          placeholder="请输入终端ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="终端名称" prop="terminalName">
        <el-input
          v-model="queryParams.terminalName"
          placeholder="请输入终端名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="别名/曾用名" prop="aliasName">
        <el-input
          v-model="queryParams.aliasName"
          placeholder="请输入别名/曾用名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="终端大类" prop="terminalCategory">
        <el-input
          v-model="queryParams.terminalCategory"
          placeholder="请输入终端大类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="终端小类" prop="terminalSubcategory">
        <el-input
          v-model="queryParams.terminalSubcategory"
          placeholder="请输入终端小类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="终端性质" prop="terminalNature">
        <el-input
          v-model="queryParams.terminalNature"
          placeholder="请输入终端性质"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="几级医院" prop="hospitalLevel">
        <el-input
          v-model="queryParams.hospitalLevel"
          placeholder="请输入几级医院"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="几等医院" prop="hospitalGrade">
        <el-input
          v-model="queryParams.hospitalGrade"
          placeholder="请输入几等医院"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="定点医保" prop="medicalInsurance">
        <el-input
          v-model="queryParams.medicalInsurance"
          placeholder="请输入定点医保"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="门诊量(人次/日)" prop="outpatientVolume">
        <el-input
          v-model="queryParams.outpatientVolume"
          placeholder="请输入门诊量(人次/日)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="床位数(张)" prop="bedCount">
        <el-input
          v-model="queryParams.bedCount"
          placeholder="请输入床位数(张)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在省份" prop="province">
        <el-input
          v-model="queryParams.province"
          placeholder="请输入所在省份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在城市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入所在城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在区县" prop="district">
        <el-input
          v-model="queryParams.district"
          placeholder="请输入所在区县"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理商数(家)" prop="agentCount">
        <el-input
          v-model="queryParams.agentCount"
          placeholder="请输入代理商数(家)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="漏斗品规数(个)" prop="funnelSpecsCount">
        <el-input
          v-model="queryParams.funnelSpecsCount"
          placeholder="请输入漏斗品规数(个)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入院品规数(个)" prop="admittedSpecsCount">
        <el-input
          v-model="queryParams.admittedSpecsCount"
          placeholder="请输入入院品规数(个)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总计采购数(盒)" prop="totalPurchaseCount">
        <el-input
          v-model="queryParams.totalPurchaseCount"
          placeholder="请输入总计采购数(盒)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="自增编号" prop="autoNumber">
        <el-input
          v-model="queryParams.autoNumber"
          placeholder="请输入自增编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="批量" prop="batchInfo">
        <el-input
          v-model="queryParams.batchInfo"
          placeholder="请输入批量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开发统计" prop="developmentStatistic">
        <el-input
          v-model="queryParams.developmentStatistic"
          placeholder="请输入开发统计"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所缺终端" prop="missingTerminal">
        <el-input
          v-model="queryParams.missingTerminal"
          placeholder="请输入所缺终端"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据来源" prop="dataSource">
        <el-input
          v-model="queryParams.dataSource"
          placeholder="请输入数据来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医保机构码" prop="medicalInsuranceCode">
        <el-input
          v-model="queryParams.medicalInsuranceCode"
          placeholder="请输入医保机构码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社会信用码" prop="socialCreditCode">
        <el-input
          v-model="queryParams.socialCreditCode"
          placeholder="请输入社会信用码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createdOn">
        <el-date-picker clearable
          v-model="queryParams.createdOn"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新时间" prop="updatedOn">
        <el-date-picker clearable
          v-model="queryParams.updatedOn"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hbs:terminalArchive:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hbs:terminalArchive:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hbs:terminalArchive:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hbs:terminalArchive:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="terminalArchiveList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="id" />
      <el-table-column label="档案状态" align="center" prop="archiveStatus" />
      <el-table-column label="开发状态" align="center" prop="developmentStatus" />
      <el-table-column label="终端ID" align="center" prop="terminal" />
      <el-table-column label="终端名称" align="center" prop="terminalName" />
      <el-table-column label="别名/曾用名" align="center" prop="aliasName" />
      <el-table-column label="终端大类" align="center" prop="terminalCategory" />
      <el-table-column label="终端小类" align="center" prop="terminalSubcategory" />
      <el-table-column label="终端性质" align="center" prop="terminalNature" />
      <el-table-column label="几级医院" align="center" prop="hospitalLevel" />
      <el-table-column label="几等医院" align="center" prop="hospitalGrade" />
      <el-table-column label="定点医保" align="center" prop="medicalInsurance" />
      <el-table-column label="门诊量(人次/日)" align="center" prop="outpatientVolume" />
      <el-table-column label="床位数(张)" align="center" prop="bedCount" />
      <el-table-column label="单位简介" align="center" prop="unitDescription" />
      <el-table-column label="所在省份" align="center" prop="province" />
      <el-table-column label="所在城市" align="center" prop="city" />
      <el-table-column label="所在区县" align="center" prop="district" />
      <el-table-column label="详细地址" align="center" prop="detailedAddress" />
      <el-table-column label="代理商数(家)" align="center" prop="agentCount" />
      <el-table-column label="漏斗品规数(个)" align="center" prop="funnelSpecsCount" />
      <el-table-column label="入院品规数(个)" align="center" prop="admittedSpecsCount" />
      <el-table-column label="总计采购数(盒)" align="center" prop="totalPurchaseCount" />
      <el-table-column label="自增编号" align="center" prop="autoNumber" />
      <el-table-column label="批量" align="center" prop="batchInfo" />
      <el-table-column label="文本" align="center" prop="textField" />
      <el-table-column label="开发统计" align="center" prop="developmentStatistic" />
      <el-table-column label="所缺终端" align="center" prop="missingTerminal" />
      <el-table-column label="数据来源" align="center" prop="dataSource" />
      <el-table-column label="机构类型" align="center" prop="institutionType" />
      <el-table-column label="医保机构码" align="center" prop="medicalInsuranceCode" />
      <el-table-column label="社会信用码" align="center" prop="socialCreditCode" />
      <el-table-column label="创建时间" align="center" prop="createdOn" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdOn, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updatedOn" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedOn, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hbs:terminalArchive:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hbs:terminalArchive:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改终端档案主档对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="终端ID" prop="terminal">
          <el-input v-model="form.terminal" placeholder="请输入终端ID" />
        </el-form-item>
        <el-form-item label="终端名称" prop="terminalName">
          <el-input v-model="form.terminalName" placeholder="请输入终端名称" />
        </el-form-item>
        <el-form-item label="别名/曾用名" prop="aliasName">
          <el-input v-model="form.aliasName" placeholder="请输入别名/曾用名" />
        </el-form-item>
        <el-form-item label="终端大类" prop="terminalCategory">
          <el-input v-model="form.terminalCategory" placeholder="请输入终端大类" />
        </el-form-item>
        <el-form-item label="终端小类" prop="terminalSubcategory">
          <el-input v-model="form.terminalSubcategory" placeholder="请输入终端小类" />
        </el-form-item>
        <el-form-item label="终端性质" prop="terminalNature">
          <el-input v-model="form.terminalNature" placeholder="请输入终端性质" />
        </el-form-item>
        <el-form-item label="几级医院" prop="hospitalLevel">
          <el-input v-model="form.hospitalLevel" placeholder="请输入几级医院" />
        </el-form-item>
        <el-form-item label="几等医院" prop="hospitalGrade">
          <el-input v-model="form.hospitalGrade" placeholder="请输入几等医院" />
        </el-form-item>
        <el-form-item label="定点医保" prop="medicalInsurance">
          <el-input v-model="form.medicalInsurance" placeholder="请输入定点医保" />
        </el-form-item>
        <el-form-item label="门诊量(人次/日)" prop="outpatientVolume">
          <el-input v-model="form.outpatientVolume" placeholder="请输入门诊量(人次/日)" />
        </el-form-item>
        <el-form-item label="床位数(张)" prop="bedCount">
          <el-input v-model="form.bedCount" placeholder="请输入床位数(张)" />
        </el-form-item>
        <el-form-item label="单位简介" prop="unitDescription">
          <el-input v-model="form.unitDescription" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所在省份" prop="province">
          <el-input v-model="form.province" placeholder="请输入所在省份" />
        </el-form-item>
        <el-form-item label="所在城市" prop="city">
          <el-input v-model="form.city" placeholder="请输入所在城市" />
        </el-form-item>
        <el-form-item label="所在区县" prop="district">
          <el-input v-model="form.district" placeholder="请输入所在区县" />
        </el-form-item>
        <el-form-item label="详细地址" prop="detailedAddress">
          <el-input v-model="form.detailedAddress" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="代理商数(家)" prop="agentCount">
          <el-input v-model="form.agentCount" placeholder="请输入代理商数(家)" />
        </el-form-item>
        <el-form-item label="漏斗品规数(个)" prop="funnelSpecsCount">
          <el-input v-model="form.funnelSpecsCount" placeholder="请输入漏斗品规数(个)" />
        </el-form-item>
        <el-form-item label="入院品规数(个)" prop="admittedSpecsCount">
          <el-input v-model="form.admittedSpecsCount" placeholder="请输入入院品规数(个)" />
        </el-form-item>
        <el-form-item label="总计采购数(盒)" prop="totalPurchaseCount">
          <el-input v-model="form.totalPurchaseCount" placeholder="请输入总计采购数(盒)" />
        </el-form-item>
        <el-form-item label="自增编号" prop="autoNumber">
          <el-input v-model="form.autoNumber" placeholder="请输入自增编号" />
        </el-form-item>
        <el-form-item label="批量" prop="batchInfo">
          <el-input v-model="form.batchInfo" placeholder="请输入批量" />
        </el-form-item>
        <el-form-item label="文本" prop="textField">
          <el-input v-model="form.textField" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="开发统计" prop="developmentStatistic">
          <el-input v-model="form.developmentStatistic" placeholder="请输入开发统计" />
        </el-form-item>
        <el-form-item label="所缺终端" prop="missingTerminal">
          <el-input v-model="form.missingTerminal" placeholder="请输入所缺终端" />
        </el-form-item>
        <el-form-item label="数据来源" prop="dataSource">
          <el-input v-model="form.dataSource" placeholder="请输入数据来源" />
        </el-form-item>
        <el-form-item label="医保机构码" prop="medicalInsuranceCode">
          <el-input v-model="form.medicalInsuranceCode" placeholder="请输入医保机构码" />
        </el-form-item>
        <el-form-item label="社会信用码" prop="socialCreditCode">
          <el-input v-model="form.socialCreditCode" placeholder="请输入社会信用码" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdOn">
          <el-date-picker clearable
            v-model="form.createdOn"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedOn">
          <el-date-picker clearable
            v-model="form.updatedOn"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTerminalArchive, getTerminalArchive, delTerminalArchive, addTerminalArchive, updateTerminalArchive } from "@/api/hbs/terminalArchive"

export default {
  name: "TerminalArchive",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 终端档案主档表格数据
      terminalArchiveList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        archiveStatus: null,
        developmentStatus: null,
        terminal: null,
        terminalName: null,
        aliasName: null,
        terminalCategory: null,
        terminalSubcategory: null,
        terminalNature: null,
        hospitalLevel: null,
        hospitalGrade: null,
        medicalInsurance: null,
        outpatientVolume: null,
        bedCount: null,
        unitDescription: null,
        province: null,
        city: null,
        district: null,
        detailedAddress: null,
        agentCount: null,
        funnelSpecsCount: null,
        admittedSpecsCount: null,
        totalPurchaseCount: null,
        autoNumber: null,
        batchInfo: null,
        textField: null,
        developmentStatistic: null,
        missingTerminal: null,
        dataSource: null,
        institutionType: null,
        medicalInsuranceCode: null,
        socialCreditCode: null,
        createdOn: null,
        updatedOn: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询终端档案主档列表 */
    getList() {
      this.loading = true
      listTerminalArchive(this.queryParams).then(response => {
        this.terminalArchiveList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        archiveStatus: null,
        developmentStatus: null,
        terminal: null,
        terminalName: null,
        aliasName: null,
        terminalCategory: null,
        terminalSubcategory: null,
        terminalNature: null,
        hospitalLevel: null,
        hospitalGrade: null,
        medicalInsurance: null,
        outpatientVolume: null,
        bedCount: null,
        unitDescription: null,
        province: null,
        city: null,
        district: null,
        detailedAddress: null,
        agentCount: null,
        funnelSpecsCount: null,
        admittedSpecsCount: null,
        totalPurchaseCount: null,
        autoNumber: null,
        batchInfo: null,
        textField: null,
        developmentStatistic: null,
        missingTerminal: null,
        dataSource: null,
        institutionType: null,
        medicalInsuranceCode: null,
        socialCreditCode: null,
        createdOn: null,
        updatedOn: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加终端档案主档"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getTerminalArchive(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改终端档案主档"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTerminalArchive(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addTerminalArchive(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除终端档案主档编号为"' + ids + '"的数据项？').then(function() {
        return delTerminalArchive(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hbs/terminalArchive/export', {
        ...this.queryParams
      }, `terminalArchive_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
